package com.bytedance.scenedemo.activity_compatibility.configuration;

import com.bytedance.scene.group.GroupScene;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.utility.ColorUtil;
import com.bytedance.scenedemo.view.ClassPathInfoTextView;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.window.dialog.ToastDialog;

/**
 * Configuration change
 *
 * @author JiangQi
 * @since 2018-04-09
 */
public class ConfigurationDemoScene extends GroupScene {

    private ComponentContainer parse;

    @Override
    public ComponentContainer onCreateView(LayoutScatter inflater, ComponentContainer container, Intent savedInstanceState) {
        parse = (ComponentContainer) inflater.parse(ResourceTable.Layout_basic_layout, container, false);
        return parse;
    }

    @Override
    public void onActivityCreated(Intent intent) {
        super.onActivityCreated(intent);
        this.getView().setBackground(ColorUtil.getMaterialColor(0));
        ClassPathInfoTextView classPathInfoTextView = (ClassPathInfoTextView) parse.findComponentById(ResourceTable.Id_class_path_info);
        classPathInfoTextView.setText(this.getClass().getName());
        Text name = (Text) parse.findComponentById(ResourceTable.Id_name);
        name.setText("请旋转屏幕");
        Button btn = (Button) parse.findComponentById(ResourceTable.Id_btn);
        btn.setVisibility(Component.HIDE);

        SceneExtensions.requireNavigationScene(this).addConfigurationChangedListener(this, listener -> {
            new ToastDialog(getApplicationContext()).setText("onConfigurationChanged").setDuration(2000).show();
        });
    }
}
